#include "ros/ros.h"
#include "ros_demo/AddTwoInts.h"

// 服务回调函数
bool add(ros_demo::AddTwoInts::Request  &req,
         ros_demo::AddTwoInts::Response &res)
{
    res.sum = req.a + req.b;
    ROS_INFO("服务请求: %ld + %ld = %ld", (long int)req.a, (long int)req.b, (long int)res.sum);
    return true;
}

int main(int argc, char **argv)
{
    // 初始化ROS节点
    ros::init(argc, argv, "add_two_ints_server");
    
    // 创建节点句柄
    ros::NodeHandle n;
    
    // 创建服务服务器
    ros::ServiceServer service = n.advertiseService("add_two_ints", add);
    
    ROS_INFO("服务服务器启动，等待加法请求...");
    
    // 进入循环，等待服务请求
    ros::spin();
    
    return 0;
}
